package toolkit;

import inputstream.StringStream;

import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Random;


public class RandomReader extends StoreReader{

	private Random numbergenerator;
	
	public RandomReader(InputStream _sourcestream) throws IOException {
		super(_sourcestream);
		this.numbergenerator=new Random(Calendar.getInstance().getTimeInMillis());
	}
	
	@Override
	public String readString(){
		return this.stringstore.get(this.numbergenerator.nextInt(this.stringstore.size()));
	}
	@Override
	public <NUMBER extends Number> NUMBER readNumber(Class<NUMBER> numbertype){
		String str=this.readString();
		if (numbertype.getSuperclass()!=Number.class){
			this.inputerror=StringStream.PARSERNOTFOUND;
			return null;
		}
		return this.getNumberFromClass(numbertype, str);
	}

}
